#ifndef EQCTRLDELEGATE_H
#define EQCTRLDELEGATE_H

#include <QItemDelegate>

class BaseDelegate : public QItemDelegate
{
    Q_OBJECT
public:
    BaseDelegate(QObject *parent = nullptr);
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
signals:
    void startEdit(QModelIndex) const;
protected:
    mutable QModelIndex m_index;
};

class SpinBoxDelegate : public BaseDelegate
{
    Q_OBJECT
public:
    SpinBoxDelegate(const int &min, const int &max, QObject *parent = nullptr);
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
public slots:
    void onValueChanged(int value);
private:
    int m_min;
    int m_max;
};

class DoubleSpinBoxDelegate : public BaseDelegate
{
    Q_OBJECT
public:
    DoubleSpinBoxDelegate(const double &min, const double &max, const double &step, const int &decimal, QObject *parent = nullptr);
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
public slots:
    void onValueChanged(double value);
private:
    double m_min;
    double m_max;
    double m_step;
    int m_decimal;
};

class QValueSpinBoxDelegate : public BaseDelegate
{
    Q_OBJECT
public:
    QValueSpinBoxDelegate(QObject *parent = nullptr);
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
public slots:
    void onValueChanged(int value);
};

class ComboBoxDelegate : public BaseDelegate
{
    Q_OBJECT
public:
    ComboBoxDelegate(QObject *parent = nullptr);
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
public slots:
    void onValueChanged(int value);
private:
    QStringList m_list;
};

class CheckBoxDelegate : public BaseDelegate
{
    Q_OBJECT
public:
    CheckBoxDelegate(QObject *parent = nullptr);
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
public slots:
    void onValueChanged(int value);
};

#endif // EQCTRLDELEGATE_H
